package com.standardoperationapp.global;

import static androidx.core.content.ContextCompat.startActivity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.standardoperationapp.activity.MainActivity;
import com.standardoperationapp.R;


public class TopMenuLayout extends LinearLayout {

    private Context mContext;
    private Button  backBtn,mainBtn;
    private TextView titleTv;

    public TopMenuLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mContext = context;

        LayoutInflater.from(context).inflate(R.layout.activity_top_menu, this);

        mainBtn =(Button)findViewById(R.id.mainBtn);
        mainBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
               startActivity(mContext,new Intent(mContext, MainActivity.class),null);
            }
        });
        backBtn=(Button)findViewById(R.id.backBtn);
        backBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((Activity) getContext()).finish();
            }
        });
        titleTv = (TextView)findViewById(R.id.top_titleTv);
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TitleBorderLayout);
        String title = (String) a.getText(R.styleable.TitleBorderLayout_title);
        if (title!=null && !title.isEmpty()) {
            titleTv.setText( title);
        } else {
            titleTv.setText( getTitleString());
        }
    }
    public String  getTitleString() {
        String title = "物资管理";
        if (GlobalVaries.uiType == GlobalVaries.DOOR_MANAGE) {
            title = "通道门管理";
        } else if (GlobalVaries.uiType == GlobalVaries.DOOR_EMERGENCY) {
            title = "紧急开锁";
        } else if (GlobalVaries.uiType == GlobalVaries.DOOR_APPLY_KEY) {
            title = "申请开门钥匙";
        }
        return title;
    }
    public void  setTitle(String str) {
        titleTv.setText( str);
    }
}